import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Window.Type;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTextPane;

public class frmTu extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private boolean result = false;
	private JTextField txtTu;
	private frmMain frmParent;

	/**
	 * Create the dialog.
	 */
	public frmTu(Frame owner, boolean modal) {
		super(owner, modal);
		this.frmParent = (frmMain) owner;
		setTitle("Th\u00EAm t\u1EEB m\u1EDBi");
		setResizable(false);
		setModal(true);
		setType(Type.UTILITY);
		setBounds(100, 100, 374, 184);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel lblNewLabel = new JLabel("T\u1EEB:");
			lblNewLabel.setBounds(10, 11, 46, 14);
			contentPanel.add(lblNewLabel);
		}
		{
			txtTu = new JTextField();
			txtTu.setBounds(61, 8, 204, 20);
			contentPanel.add(txtTu);
			txtTu.setColumns(10);
		}
		{
			JLabel lblNgha = new JLabel("Ngh\u0129a:");
			lblNgha.setBounds(10, 41, 46, 14);
			contentPanel.add(lblNgha);
		}
		{
			JTextPane txtNghia = new JTextPane();
			txtNghia.setBounds(61, 35, 204, 50);
			contentPanel.add(txtNghia);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						if (frmParent.checkWordExist(txtTu.getText())) {
							JOptionPane.showMessageDialog(frmTu.this,
									"Từ này đã tồn tài", "Lỗi",
									JOptionPane.ERROR_MESSAGE);
							result = false;
						} else {
							result = true;
							setVisible(false);
						}
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						result = false;
						setVisible(false);
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2
				- this.getSize().height / 2);
	}

	public boolean showDialog() {
		result = false;
		setVisible(true);
		return result;
	}
}
